package cs271.examples.sorting;

import java.util.List;
import java.util.PriorityQueue;
import java.util.*;

public class HeapSort {

	/**
	 * Here is a very naive implementation of the heapsort, but it should
	 * convey the general idea.
	 * @param unsorted
	 * @return
	 */
	public static List<Integer> heapSort(List<Integer> unsorted) {
		PriorityQueue<Integer> heap = new PriorityQueue<Integer>();
		List<Integer> sorted = new ArrayList<Integer>(unsorted.size());
		for(Integer i: unsorted) {
			heap.add(i);
		}
		while(!heap.isEmpty()) {
			sorted.add(heap.remove());
		}
		return sorted;
	}
	
	public static void main(String[] args) {
		List<Integer> a = new ArrayList<Integer>();
		a.add(5);
		a.add(2);
		a.add(7);
		a.add(0);
		
		System.out.println(heapSort(a));
	}
}
